package com.szh.lenovo0520.IntentService;

import android.app.IntentService;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.SystemClock;
import android.util.Log;

import androidx.annotation.Nullable;

public class MyIntentService extends IntentService {

    private static final String TAG = "MyIntentService";

    @Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "onCreate: ");
    }

    /**
     * Creates an IntentService.  Invoked by your subclass's constructor.
     *
     * @param name Used to name the worker thread, important only for debugging.
     */
    public MyIntentService(String name) {
        super(name);
        Log.d(TAG, "有参构造 ");
    }

    public MyIntentService() {
        super("hahaha");
        Log.d(TAG, "无参构造 ");
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
     fun1(intent);
     fun2(intent);
    }

    public void fun1(Intent intent){
        String s = intent.getStringExtra("task1");
        if (s!=null&&s.length()>0) {
            for (int i = 1; i <=10 ; i++) {
                Log.d( "fun1: ",s+"---"+i);
                SystemClock.sleep(1000);
            }
        }
    }
    public void fun2(Intent intent){
        String s = intent.getStringExtra("task2");
        if (s!=null&&s.length()>0) {
            for (int i = 1; i <=10 ; i++) {
                Log.d( "fun2: ",s+"---"+i);
                SystemClock.sleep(1000);
            }
        }
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy: ");
    }
}
